<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.PreparedStatement" %>
<%@ page import="java.sql.ResultSet" %><%--
  Created by IntelliJ IDEA.
  User: LH
  Date: 2022/10/1
  Time: 11:37
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    //1.加载驱动程序
    Class.forName("com.mysql.cj.jdbc.Driver");
    //2.建立与数据库的连接
    String url = "jdbc:mysql://localhost:3306/javaeelab";
    Connection conn = DriverManager.getConnection(url, "root", "root");
    //3.创建命令对象
    String sql="select * from  tb_student where name like ?";
    PreparedStatement ps = conn.prepareStatement(sql);
    String name = request.getParameter("name");
    ps.setString(1,'%'+name+'%');
    ResultSet rs = ps.executeQuery();
    out.println("<table border='1'>");
    out.println("<tr><td>id</td><td>num</td>><td>name</td><td>gender</td><td>major<t/d></tr>");
    while(rs.next()){
        out.println("<tr>");
        out.println("<td>"+rs.getString("id")+"</td>");
        out.println("<td>"+rs.getString("num")+"</td>");
        out.println("<td>"+rs.getString("name")+"</td>");
        out.println("<td>"+rs.getString("gender")+"</td>");
        out.println("<td>"+rs.getString("major")+"</td>");
        out.println("</tr>");
    }
    out.println("</table>");
%>
</body>
</html>
